package com.action;

import java.io.Serializable;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.entity.Department;
import com.entity.Person;
import com.opensymphony.xwork2.ActionSupport;
import com.service.DepartmentService;
import com.service.PersonService;

public class UpdateFindAction extends BaseAction implements Serializable {
	@Autowired
	private PersonService personService;
	@Autowired
	private DepartmentService departmentService;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Person person;
	private Department department;
	List<Department> departments;
	private List<Person> persons;
	private String type;
	private Integer ok;
	
	public Integer getOk() {
		return ok;
	}

	public void setOk(Integer ok) {
		this.ok = ok;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<Person> getPersons() {
		return persons;
	}

	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}

	public List<Department> getDepartments() {
		return departments;
	}

	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}
	 @Action(value = "update-person", results = { @Result(name = "success", location = "update-person.jsp") })
	@Override
	public String execute() throws Exception {
		if (person != null) {	
	
			person = personService.findById(person.getId());			
		}
		

		return "success";
	}
	 @Action(value = "update-dep", results = { @Result(name = "success", location = "update-dep.jsp") })
	
		public String updateDep() throws Exception {	
			if (department != null) {				
				department = departmentService.findById(department.getId());	
			}
			return "success";
		}

}
